///////////////////////////////////////////////////////////////////////////////
// Company: University of Cincinnati
// Author: Jordan Ross, Ben Gentry, Bryan Butsch
//
// Created Date: 10/08/2013
// Design Name:
// Module Name: seg7_dec
// Project Name: top_level
// Target Devices: Cyclone II EP2C20F484C7
// Tool Versions: Quartus 13.0
// Description: This module decodes a data value into the proper seven segment
//              value.
// 
// Dependencies: None
// 
// Revision:
// 0.01 - File Created
//
// Additional Comments:
//
///////////////////////////////////////////////////////////////////////////////
module seg7_dec(Enable, Data, Q, Resetn);
    parameter n = 7;
    input [8:0] Data;
    input Enable, Resetn;
    output reg [n-1:0] Q;
    
    parameter ZERO = 9'b000000000, ONE = 9'b000000001, TWO = 9'b000000010, THREE = 9'b000000011; 
    parameter FOUR = 9'b000000100, FIVE = 9'b000000101, SIX = 9'b000000110, SEVEN = 9'b000000111; 
    parameter EIGHT = 9'b000001000, NINE = 9'b000001001, A = 9'b000001010, B = 9'b000001011;  
    parameter C = 9'b000001100, D = 9'b000001101, E = 9'b000001110, F = 9'b000001111;
        
    // have the 7seg displays off to start with
	 initial begin
        Q <= 7'b1111111;
    end
    
	 // encode the data 
    always @(Data or Enable) begin            
        if (!Resetn)
				Q = 7'b1111111;
		  else if (Enable)
            begin 
            case (Data)
                ZERO:       Q = 7'b1000000;
                ONE:        Q = 7'b1111001;
                TWO:        Q = 7'b0100100;
                THREE:      Q = 7'b0110000;
                FOUR:       Q = 7'b0011001;
                FIVE:       Q = 7'b0010010;
                SIX:        Q = 7'b0000010;
                SEVEN:      Q = 7'b1111000;
                EIGHT:      Q = 7'b0000000;
                NINE:       Q = 7'b0010000;
                A:          Q = 7'b0001000;
                B:          Q = 7'b0000011;
                C:          Q = 7'b1000110;
                D:          Q = 7'b0100001;
                E:          Q = 7'b0000110;
                F:          Q = 7'b0001110;
                default:    Q = 7'b1111111;
            endcase
            end 
        else        
            Q = 7'b1111111;
    end
	 
endmodule
